@echo off
SETLOCAL ENABLEEXTENSIONS
chcp 65001 >nul
cd /d %~dp0

SET MODE=%1
IF "%MODE%"=="--dev" GOTO DEV
IF "%MODE%"=="-d" GOTO DEV
IF "%MODE%"=="dev" GOTO DEV
IF "%MODE%"=="development" GOTO DEV


:PROD
echo 🚀 Starting AI-Editor in [PRODUCTION] mode...


start /B uvicorn server.main:app --port 8000


pushd "%~dp0web"
start /B pnpm start
popd

GOTO END

:DEV
echo 🚧 Starting AI-Editor in [DEVELOPMENT] mode...

for /f "tokens=5" %%a in ('netstat -ano ^| findstr :8000 ^| findstr LISTENING') do (
    echo ⚠️ 端口 8000 被占用，结束进程 %%a ...
    taskkill /F /PID %%a >nul 2>nul
)


start /B uvicorn server.main:app --reload --port 8000

pushd "%~dp0web"
start /B pnpm run dev
popd

GOTO END

:END
ENDLOCAL
